//
//  LoginViewController.m
//  MyProject
//
//  Created by dllo on 15/11/1.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "UMSocial.h"    //三方登陆

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface LoginViewController ()<UITextFieldDelegate, UMSocialUIDelegate>

@property(nonatomic, retain)UITextField *textLoginUser;
@property(nonatomic, retain)UITextField *textLoginPass;
@property(nonatomic, retain)UIButton *buttonDisplay;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self touxiang];
    [self yonghuming];
    [self mima];
    [self wanjimima];
    [self denglu];
    [self sanfangdenglu];
    [self xianshi];
    [self zhuce];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark - 头像
- (void)touxiang{
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 35, HEIGHT / 100 * 10, WIDTH / 100 * 30, HEIGHT / 100 * 12)];
    [self.view addSubview:view];
//    view.layer.borderWidth = 1;
    view.layer.cornerRadius = 50;
    view.image = [UIImage imageNamed:@"touxiang.png"];
    view.layer.masksToBounds = YES;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 100 * 35, HEIGHT / 100 * 22, WIDTH / 100 * 30, HEIGHT / 100 * 10)];
    [self.view addSubview:label];
//    label.layer.borderWidth = 1;
    label.layer.cornerRadius = 10;
    label.font = [UIFont systemFontOfSize:25 weight:20];
    label.text = @"微微一笑";
}





#pragma mark - 用户名
- (void)yonghuming{
    //      用户名
    UILabel *labelLoginUser = [[UILabel alloc] initWithFrame:CGRectMake(0,  HEIGHT / 100 * 34, WIDTH / 100 * 35, HEIGHT / 100 * 5)];
    labelLoginUser.backgroundColor = [UIColor clearColor];
    [self.view addSubview:labelLoginUser];
    labelLoginUser.text = @"用户名 :";
    labelLoginUser.textAlignment = NSTextAlignmentCenter;
    labelLoginUser.font = [UIFont systemFontOfSize:25];
    labelLoginUser.textColor = [UIColor blueColor];
    
    
    //      填写用户名
    self.textLoginUser = [[UITextField alloc] initWithFrame:CGRectMake(WIDTH / 100 * 30, HEIGHT / 100 * 34, WIDTH / 100 * 55, HEIGHT / 100 * 5)];
    self.textLoginUser.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.textLoginUser];
//    self.textLoginUser.layer.borderWidth = 1;
    self.textLoginUser.layer.cornerRadius = 10;
    self.textLoginUser.layer.masksToBounds = YES;
    self.textLoginUser.placeholder = @"请输入用户名";
    self.textLoginUser.textAlignment = NSTextAlignmentCenter;
    self.textLoginUser.font = [UIFont systemFontOfSize:25];
    self.textLoginUser.delegate = self;
    self.textLoginUser.textColor = [UIColor blueColor];
}




#pragma mark - 密码
- (void)mima{
    
    //      密码
    UILabel *labelLoginPass = [[UILabel alloc] initWithFrame:CGRectMake(0, HEIGHT / 100 * 44, WIDTH / 100 * 35, HEIGHT / 100 * 5)];
    labelLoginPass.backgroundColor = [UIColor clearColor];
    [self.view addSubview:labelLoginPass];
    labelLoginPass.text = @"密码 :";
    labelLoginPass.textAlignment = NSTextAlignmentCenter;
    labelLoginPass.font = [UIFont systemFontOfSize:25];
    labelLoginPass.textColor = [UIColor blueColor];
    
    
    //      填写密码
    self.textLoginPass = [[UITextField alloc] initWithFrame:CGRectMake(WIDTH / 100 * 30, HEIGHT / 100 * 44, WIDTH / 100 * 55, HEIGHT / 100 * 5)];
    self.textLoginPass.backgroundColor = [UIColor clearColor];
//    self.textLoginPass.layer.borderWidth = 1;
    self.textLoginPass.layer.cornerRadius = 10;
    self.textLoginPass.layer.masksToBounds = YES;
    self.textLoginPass.secureTextEntry = YES;
    self.textLoginPass.clearButtonMode = UITextFieldViewModeAlways;
    self.textLoginPass.placeholder = @"请输入密码";
    self.textLoginPass.textAlignment = NSTextAlignmentCenter;
    self.textLoginPass.font = [UIFont systemFontOfSize:25];
    self.textLoginPass.delegate = self;
    self.textLoginPass.textColor = [UIColor blueColor];
    
}


#pragma mark - 忘记密码
- (void)wanjimima{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:button];
    button.frame = CGRectMake(WIDTH / 100 * 55, HEIGHT / 100 * 55, WIDTH / 100 * 30, HEIGHT / 100 * 2);
    [button setTitle:@"忘记密码?" forState:UIControlStateNormal];
//    button.layer.borderWidth = 1;
    button.tintColor = [UIColor colorWithRed:0.5 green:1 blue:0.9 alpha:1];
    
}








#pragma mark - 登录按钮
- (void)denglu{
    
    //      登陆按钮
    UIButton *buttonLogin = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonLogin.frame = CGRectMake(WIDTH / 100 * 25, HEIGHT / 100 * 60, WIDTH / 100 * 55, HEIGHT / 100 * 5);
    buttonLogin.backgroundColor = [UIColor clearColor];
    [self.view addSubview:buttonLogin];
//    buttonLogin.layer.borderWidth = 1;
    buttonLogin.layer.cornerRadius = 10;
    [buttonLogin setTitle:@"登陆" forState:UIControlStateNormal];
    buttonLogin.titleLabel.font = [UIFont systemFontOfSize:25];
    [buttonLogin addTarget:self action:@selector(clickLogin:) forControlEvents:UIControlEventTouchUpInside];
    buttonLogin.backgroundColor = [UIColor colorWithRed:0.5 green:1 blue:0.9 alpha:1];
    buttonLogin.tintColor = [UIColor whiteColor];
    buttonLogin.tintColor = [UIColor blueColor];
    
    UIView *viewline = [[UIView alloc] initWithFrame:CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 68, WIDTH / 100 * 80, HEIGHT / 100)];
    [self.view addSubview:viewline];
    viewline.backgroundColor = [UIColor blueColor];
}

//      登陆按钮
- (void)clickLogin : (UIButton *)button {
    if ([_textLoginUser.text isEqualToString:@""] || [_textLoginPass.text isEqualToString:@""]) {
        UIAlertView *alertLoginView = [[UIAlertView alloc] initWithTitle:@"登陆信息错误" message:@"请重新登陆" delegate:self cancelButtonTitle:@"Cannel" otherButtonTitles:@"OK", nil];
        [alertLoginView show];
    } else {
        UIAlertView *alertLoginView = [[UIAlertView alloc] initWithTitle:@"登陆成功" message:@"" delegate:self cancelButtonTitle:@"Cannel" otherButtonTitles:@"OK", nil];
        [alertLoginView show];
    }
}




#pragma mark - 显示按钮
- (void)xianshi{
    
    //      显示按钮
    self.buttonDisplay = [UIButton buttonWithType:UIButtonTypeSystem];
    self.buttonDisplay.frame = CGRectMake(310, 300, 50, 20);
    self.buttonDisplay.backgroundColor = [UIColor clearColor];
//    self.buttonDisplay.layer.borderWidth = 1;
    self.buttonDisplay.layer.cornerRadius = 10;
    self.buttonDisplay.layer.masksToBounds = YES;
    [self.view addSubview:self.buttonDisplay];
    [self.buttonDisplay setBackgroundImage:[UIImage imageNamed:@"Off.jpg"] forState:UIControlStateNormal];
    self.buttonDisplay.titleLabel.font = [UIFont systemFontOfSize:25];
    [self.buttonDisplay addTarget:self action:@selector(clickDisplay:) forControlEvents:UIControlEventTouchUpInside];
}

//      显示按钮
- (void)clickDisplay : (UIButton *)button {
    if (self.textLoginPass.secureTextEntry) {
        [self.buttonDisplay setBackgroundImage:[UIImage imageNamed:@"On.jpg"] forState:UIControlStateNormal];
    } else {
        [self.buttonDisplay setBackgroundImage:[UIImage imageNamed:@"Off.jpg"] forState:UIControlStateNormal];
    }
    self.textLoginPass.secureTextEntry = !self.textLoginPass.secureTextEntry;
}


//      收回键盘
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}



#pragma mark - 三方登录
- (void)sanfangdenglu{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:button];
    button.frame = CGRectMake(WIDTH / 100 * 10, HEIGHT / 100 * 70, WIDTH / 100 * 10, WIDTH / 100 * 10);
//    button.layer.borderWidth = 1;
    button.layer.cornerRadius = 20;
//    [button setTitle:@"微博登陆" forState:UIControlStateNormal];
//    button.layer.borderWidth = 1;
    [button addTarget:self action:@selector(sanfang:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"weibo.png"] forState:UIControlStateNormal];
    
    
    UIButton *buttonSec = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:buttonSec];
    buttonSec.frame = CGRectMake(WIDTH / 100 * 80, HEIGHT / 100 * 70, WIDTH / 100 * 10, WIDTH / 100 * 10);
//    buttonSec.layer.borderWidth = 1;
    buttonSec.layer.cornerRadius = 20;
//    [buttonSec setTitle:@"qq 登录" forState:UIControlStateNormal];
//    buttonSec.layer.borderWidth = 1;
    [buttonSec addTarget:self action:@selector(sanfang:) forControlEvents:UIControlEventTouchUpInside];
    [buttonSec setImage:[UIImage imageNamed:@"qq.png"] forState:UIControlStateNormal];
}


- (void)sanfang:(UIButton *)button{
    
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"507fcab25270157b37000010"
                                      shareText:@"你要分享的文字"
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToQQ,nil]
                                       delegate:self];
    
}



//- (void)takeValue{
//
//    RegisterViewController *registerView = [[RegisterViewController alloc] init];
//    self.textLoginUser.text = registerView.textRegisterUser.text;
//
//}




#pragma mark - 注册
- (void)zhuce{
    
    //      注册按钮
    UIButton *buttonRegister = [UIButton buttonWithType:UIButtonTypeSystem];
    buttonRegister.frame = CGRectMake(WIDTH / 100 * 30, HEIGHT / 100 * 75, WIDTH / 100 * 30, WIDTH / 100 * 10);
    buttonRegister.backgroundColor = [UIColor clearColor];
    [self.view addSubview:buttonRegister];
    //    buttonRegister.layer.borderWidth = 1;
    //    buttonRegister.layer.cornerRadius = 10;
    [buttonRegister setTitle:@"注册" forState:UIControlStateNormal];
    buttonRegister.titleLabel.font = [UIFont systemFontOfSize:25];
    [buttonRegister addTarget:self action:@selector(clickRegister:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)clickRegister:(UIButton *)button{
    
    RegisterViewController *registerView = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerView animated:YES];
    
}










@end













